package com.xiaowu.datajpa.aop;

import com.xiaowu.datajpa.exception.ResultException;
import com.xiaowu.datajpa.vo.result.Result;
import com.xiaowu.datajpa.utils.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        if(e instanceof ResultException){
            ResultException resultException = (ResultException) e;
            return ResultUtil.error(resultException.getCode(),resultException.getMessage());
        }
        return ResultUtil.error(-999, e.getMessage());
    }
}
